/**
 * 
 */
package java8;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

/**
 * @author zhongfang
 *
 */

public class LambdaTest {
	 class Person{
			int age;
			int gender;
			String email;
			int getAge(){
				return this.age;
			}
			
			String getEmailAddress(){
				return this.email;
			}
		}
	public static <X, Y> void processElements(
		    Iterable<X> source,
		    Predicate<X> tester,
		    Function <X, Y> mapper,
		    Consumer<Y> block) {
		    for (X p : source) {
		        if (tester.test(p)) {
		            Y data = mapper.apply(p);
		            block.accept(data);
		        }
		    }
		   
		}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		List<Person> roster=new ArrayList<Person>();
		
		 processElements(
				    roster,p -> p.getAge() >= 18
				        && p.getAge() <= 25,
				    p -> p.getEmailAddress(),
				    email -> System.out.println(email)
				);
	}

}
